package com.flower.service.impl;

import com.flower.service.OrderService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @ClassName OrderServiceImpl
 * @Description TODO
 * @Author 张晓焕
 * @Date 2022/6/13 9:35
 * @Version 1.0
 */
@Service
public class OrderServiceImpl implements OrderService , Callable<String> {
    @Autowired
    ThreadPoolExecutor executor;
    volatile public static boolean  iswait=true;
    @Override
    public String call( ) throws Exception {
        if (iswait) {
            iswait=false;
            Thread.sleep(5000);
            return "线程睡眠5秒";
        }else {
            iswait=true;
            return "线程没有睡眠";
        }
    }

    @Override
    public String testSync() throws ExecutionException, InterruptedException {
        String res="";
        final Future<String> result = executor.submit(new OrderServiceImpl());
        System.out.println("没有阻塞");
        // 获取结果发生阻塞 后面所有都会发生阻塞
      //  res=result.get();
        System.out.println("阻塞结束");
        return "aaaaa";

    }
}
